CPRE := @
ifeq ($(V),1)
CPRE :=
VERB := --verbose
endif

MK_GENERATED_IMGS_PATH:=generated
BOARD_NAME:=$(shell cat package.yaml | grep board_name | sed 's/[[:space:]\"]//g' | awk -F":" '{print $$2}')
BOARD_PATH:=../../boards/csky/$(BOARD_NAME)
DSPFW_BIN=../../components/voice_mit/pangu/cpu2
DSPFW_ELF=../../components/voice_mit/pangu/cpu2.elf

CONFIG_LDF:=${BOARD_PATH}/configs/gcc_eflash.ld.S

.PHONY:startup
startup: all

all:
	$(CPRE) cp ${CONFIG_LDF} ./
	$(CPRE) scons $(VERB) -j4
	@echo YoC SDK Done

	@echo [INFO] Create bin files
	$(CPRE) product image $(MK_GENERATED_IMGS_PATH)/images.zip -i $(MK_GENERATED_IMGS_PATH)/data -l -p
	$(CPRE) product image $(MK_GENERATED_IMGS_PATH)/images.zip -e $(MK_GENERATED_IMGS_PATH) -x
	$(CPRE) cp $(MK_GENERATED_IMGS_PATH)/data/prim $(DSPFW_BIN)
	$(CPRE) cp yoc.elf $(DSPFW_ELF)

.PHONY:flash
flash:
	$(CPRE) product flash $(MK_GENERATED_IMGS_PATH)/images.zip -w prim

.PHONY:flashall
flashall:
	$(CPRE) product flash $(MK_GENERATED_IMGS_PATH)/images.zip -a

sdk:
	$(CPRE) yoc sdk
.PHONY:clean
clean:
	$(CPRE) rm yoc_sdk -rf
	$(CPRE) scons -c
	$(CPRE) find . -name "*.[od]" -delete
